<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 010-12345678 / 1234-1234567
        var rg = /^\d{3}-\d{8}|\d{4}-\d{7}$/
        // var rg = /^\d{3,4}-\d{7,8}$/ //  简写但可能有bug  0103-12345678 例如这样就不对了吧 但是如果用这个验证就返回true
        console.log(rg.test('010-12345678'));
        console.log(rg.test('0103-1234567'));
    </script>
</body>
</html>